﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Globalization;
using System.Data.SqlClient;
using System.Configuration;

public partial class Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (!Page.IsPostBack)
        {
            SetYearDropDownValue();
        }
        //if (Session["Role"] != null)
        //{
        //    if (Session["Role"] == "Admin")
        //    {
        //        AdminLoginPopup.Visible = false;
        //        CreateUserPopup.Visible = true;
        //    }
        //    else
        //    {
        //        AdminLoginPopup.Visible = true;
        //        CreateUserPopup.Visible = false;
        //    }
        //}
        //else
        //{
        //    AdminLoginPopup.Visible = true;
        //    CreateUserPopup.Visible = false;
        //}
    }

    protected void CreateUserClick(object sender, EventArgs e)
    {
        //  PersianCalendar persianCalendar = new PersianCalendar();
        //        string year = persianCalendar.GetYear(DateTime.Now).ToString().Replace("13", "");
        //string year = "89";

        //string connectionName = string.Format("ConnectionString{0}", year.Replace("/", ""));
        //DataClassesDataContext dataCotext = new DataClassesDataContext(ConfigurationManager.ConnectionStrings[connectionName].ConnectionString);
        //Login _Login = new Login();
        //_Login.FirstName = UserFirstNameTextBox.Text;
        //_Login.LastName = UserLastNameTextBox.Text;
        //_Login.Password = UserPasswordTextBox.Text;
        //_Login.RoleID = byte.Parse(UserRoleRadioButtonList.SelectedValue);
        //_Login.UserName = UserUserNameTextBox.Text;
        //dataCotext.Logins.Attach(_Login);
        //dataCotext.SubmitChanges();
    }

    private void SetYearDropDownValue()
    {
        PersianCalendar persianCalendar = new PersianCalendar();
        int currentYear = persianCalendar.GetYear(DateTime.Now);
        for (int i = 0; i <= 3; i++)
        {
            ListItem listItem = new ListItem();
            listItem.Value = listItem.Text = (currentYear - i).ToString();
            YearDropDownList.Items.Add(listItem);
        }
    }

    protected void LoginPatientClick(object sender, EventArgs e)
    {
        string year = GetYear();
        ///////if (LoginUser.IsSecurePatient(year, PhoneTextBox.Text, CodeTextBox.Text))
        /////////Response.Redirect(string.Format("{0}/{1}/{2}/_Patient", PhoneTextBox.Text, CodeTextBox.Text, year));        
        Response.Redirect(string.Format("Patient/ShowToPatient.aspx?tel={0}&code={1}&year={2}", PhoneTextBox.Text, CodeTextBox.Text, year));
    }

    private string GetYear()
    {
        return YearDropDownList.SelectedValue.Substring(2, 2) + "/";
    }

    protected void LoginDoctorClick(object sender, EventArgs e)
    {

        PersianCalendar persianCalendar = new PersianCalendar();
        string year = persianCalendar.GetYear(DateTime.Now).ToString().Replace("13", "");
        year = "88";
        //Doctor => RoleId = 2
        //if (LoginUser.IsSecure(DoctorPassowrdTextBox.Text, DoctorUserNameTextBox.Text, year, 2))
        /////////Response.Redirect(string.Format("{0}/{1}/_Doctor", DoctorUserNameTextBox.Text, year));      
        Response.Redirect(string.Format("Doctor/ShowToDoctor.aspx?username={0}&year={1}", DoctorUserNameTextBox.Text, year));
    }
}